package servlet.home;

import com.alibaba.fastjson.JSONObject;
import po.User;
import utils.ResultData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 *      头部显示
 */
@WebServlet(urlPatterns = "/baseServlet")
public class BaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User)session.getAttribute("userKey");
        String name = user.getName();
        ResultData resultData = ResultData.buildData(name);
        Object o = JSONObject.toJSON(resultData);
        resp.getWriter().print(o.toString());
    }
}
